/**
 * 
 */
package edu.tongji.engine.def;

import edu.tongji.engine.common.Log;
import edu.tongji.engine.db.pojo.Actor;
import edu.tongji.engine.exe.ExecutionContext;
import edu.tongji.engine.exe.Token;
import edu.tongji.engine.taskmgr.TaskMgrService;

/**
 * @author David Fei
 *
 */
public class ActivityNode extends Node implements java.io.Serializable{
	
	private int mail;
	
	private Actor actor;
	
	//private TaskMgrService taskService;
	
	public ActivityNode(){
		//taskService = new TaskMgrService();
		this.setType_name("ActivityNode");
	}
	@Override
	public void EnterEnvent(Token token) {
		// TODO Auto-generated method stub
		
		
		try{
			if (this.getEnterEventHandler()!=null){
				this.createTask(this,token);
			
//			IHandler eventHandler = 
//				(IHandler)Class.forName(this.getEnterEventHandler()).newInstance();
//			eventHandler.execute(context);
			System.out.println(this.getName()+" enter event ...");
			
			}
		}
		catch( Exception e ){
			System.out.println(e.toString());
			Log.getLoger().loger.error("EnterEvent Error", e);
		}
		
	}

	@Override
	public void LeaveEvent(Token token) {
		// TODO Auto-generated method stub
		try{
			if (this.getLeaveEventHandler()!=null){
				this.createTask(this,token);
			}
//			IHandler eventHandler = 
//				(IHandler)Class.forName(this.getEnterEventHandler()).newInstance();
//			eventHandler.execute(context);
			System.out.println(this.getName()+" leave event ...");
		}
		catch( Exception e ){
			System.out.println(e.toString());
			Log.getLoger().loger.error("LeaveEvent Error", e);
		}
	}
	
	private void createTask(ActivityNode node,Token token){
		TaskMgrService taskService = new TaskMgrService();
		taskService.createTask(node, token);
	}
	
	public int getMail() {
		return mail;
	}
	public void setMail(int mail) {
		this.mail = mail;
	}
	public Actor getActor() {
		return actor;
	}
	public void setActor(Actor actor) {
		this.actor = actor;
	}

}
